<?php

use app\assets\ApiAsset;
use app\assets\LayerAsset;
use app\assets\MaskedInputAsset;
use app\assets\TableAsset;
use app\widgets\LinkPager;
use app\widgets\ManagerTableOp;
use yii\helpers\Html;
use yii\helpers\Url;

/**
 * @var $this yii\web\View
 * @var $logList app\models\AgentLog[]
 * @var $pagination yii\data\Pagination
 */

ApiAsset::register($this);
LayerAsset::register($this);
MaskedInputAsset::register($this);
TableAsset::register($this);

$this->title = '代理商日志列表';
$this->params['breadcrumbs'][] = '用户管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
<div class="form-group">
    <label for="search_username" class="sr-only">Username</label>
    <?php echo Html::textInput('search_username', Yii::$app->request->get('search_username'), ['id'=>'search_username', 'class'=>'form-control', 'placeholder'=>'用户名', 'style'=>'max-width:100px;']);?>
</div>
<div class="form-group">
    <label for="search_info" class="sr-only">Info</label>
    <?php echo Html::textInput('search_info', Yii::$app->request->get('search_info'), ['id'=>'search_info', 'class'=>'form-control', 'placeholder'=>'操作']);?>
</div>
<div class="form-group">
    <label for="search_start_date" class="sr-only">StartDate</label>
    <?php echo Html::textInput('search_start_date', Yii::$app->request->get('search_start_date'), ['id'=>'search_start_date', 'class'=>'form-control masked', 'placeholder'=>'开始日期', 'data-mask'=>'9999-99-99', 'style'=>'max-width:90px;']);?>
    -
    <?php echo Html::textInput('search_end_date', Yii::$app->request->get('search_end_date'), ['id'=>'search_end_date', 'class'=>'form-control masked', 'placeholder'=>'结束日期', 'data-mask'=>'9999-99-99', 'style'=>'max-width:90px;']);?>
</div>
<div class="form-group">
    <button class="btn btn-primary btn-sm">搜索</button>
</div>
<?php echo Html::endForm();?>
<table class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
        <th class="center">
            <label class="pos-rel">
                <input type="checkbox" class="ace" />
                <span class="lbl"></span>
            </label>
        </th>
        <th>代理商</th>
        <th>类型</th>
        <th>时间</th>
        <th>信息</th>
        <th>操作</th>
    </tr>
    </thead>

    <tbody>
    <?php foreach ($logList as $log) {?>
        <tr>
            <td class="center"><label class="pos-rel"><input type="checkbox" class="ace" value="<?php echo $log->id;?>" /><span class="lbl"><?php echo $log->id;?></span></label></td>
            <td><?php echo Html::a(Html::encode($log->agent->username), ['/admin/user/agent-view', 'id' => $log->agent_id]);?></td>
            <td><?php echo $log->type;?></td>
            <td><?php echo Yii::$app->formatter->asDatetime($log->time);?></td>
            <td><?php echo Html::encode($log->info);?></td>
            <td><?php echo ManagerTableOp::widget(['items' => [
                    ['icon' => 'fa fa-info-circle', 'onclick' => 'showLogData(' . $log->id . ')', 'btn_class' => 'btn btn-xs btn-default', 'tip' => '详情'],
                ]]);?></td>
        </tr>
    <?php }?>
    </tbody>
</table>
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
<script>
    /**
     * 显示日志数据
     * @param id 日志编号
     */
    function showLogData(id) {
        $.getJSON('<?php echo Url::to(['/admin/user/agent-log-detail']);?>', {id: id}, function (json) {
            if (callback(json)) {
                layer.open({
                    type: 1,
                    title: json['log']['info'],
                    closeBtn: 0,
                    shadeClose: true,
                    content: '<pre>' + json['log']['data'] + '</pre>'
                });
            }
        });
    }
</script>
